<template>
	<om-formsub-outer :index="index" :checkedit="checkedit">
		<om-autoform ref="autoform" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {buildSubFormData, subOnLoad,getEditorTitle,changeEditor,configSelectData,hasValue} from '@/static/js/formUtil.js';
	import { ignoreHtml,ptFloat,minusF,getDateStr} from '@/static/js/common.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildSubFormData({
				orgCacheKey:"obj-year-tinstAnnualTargetPlan-title_benchmarking-inst-cache",
				exists:[]
			})
		},
		methods:{
			clearIndexId(){
				let _that = this
				_that.$refs.autoform.clear("title_benchmarking","indexId")
				_that.$refs.autoform.clear("title_benchmarking","currentNumCode")
				_that.$refs.autoform.clear("title_benchmarking","planNumCode")
			},
			changeEditorType(indexUnitName){
				let _that = this 
				_that.$refs.autoform.changeEditor("title_benchmarking","currentNumCode","type","numberbox")
				_that.$refs.autoform.changeEditor("title_benchmarking","currentNumCode","suffix",indexUnitName)
				_that.$refs.autoform.changeEditor("title_benchmarking","planNumCode","type","numberbox")
				_that.$refs.autoform.changeEditor("title_benchmarking","planNumCode","suffix",indexUnitName)
			},
			initLoad(){
				let _that = this
				let pro1 = _that.om.request("dictZero/getListByCode",{code:'38270'})
				Promise.all([pro1]).then(res=>{
					_that.$refs.autoform.changeEditor("title_benchmarking","cateCode","data",configSelectData(res[0],"code","dicname"))
					_that.$refs.autoform.initSelectIndex("title_benchmarking","cateCode")
				})
			}
		},
		onShow() {
			let _that = this
			if(_that.$refs.autoform){
				uni.getStorage({
					key:_that.orgCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data
							let formdata = _that.$refs.autoform.formdata
							formdata.indexId = d.id
							formdata.indexName = d.dicname
							formdata.indexUnitName = d.indexUnitName
							_that.changeEditorType(d.indexUnitName)
							uni.removeStorage({
								key:_that.orgCacheKey
							})
						}
					}
				})
			}
		},
		onLoad(e) {
			let _that = this
			subOnLoad(_that, e, function() {
			if(e.configDataCacheKey){
				_that.exists = _that.datas.filter((e,i)=>{
					return (i != _that.index)
				}).map(e=>e.indexId).join(",")
				uni.getStorage({
					key: e.configDataCacheKey,
					success: function(res) {
						if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
							_that.autoformdata = res.data
							Object.assign(_that.initValue, _that.formdata)
							_that.autoformdata[0].order = _that.order
							let title = getEditorTitle("title_benchmarking","indexId",_that.autoformdata)
								changeEditor("title_benchmarking","indexId",{
									link:"../../public/search/search",
									"linkParam":{
										other:JSON.stringify({
											lList:_that.exists
										}),
										url:"indexDict/getAllIndex2",
										namefield:"dicname",
										extrafield:"indexUnitName",
										notefield:"logicRelationshipName",
										initload:true,
										cachename:_that.orgCacheKey,
										placeholder:"请输入"+title
									}
								},null,_that.autoformdata)
								_that.initLoad()
							}
						}
					})
				}
				_that.$nextTick(function(){
					if(_that.$refs.autoform.formdata.indexUnitName){
						_that.changeEditorType(_that.$refs.autoform.formdata.indexUnitName)
					}
				})
			})
		}
	}
</script>

<style>
</style>                                                                                                                                                                                                                                                                                                                                                                                                                                                         
